using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ISB_iCard
{
    public partial class TnxDetails : Form
    {
        public TnxDetails()
        {
            InitializeComponent();
        }

        iCardService.Service1 objiCardService = new ISB_iCard.iCardService.Service1();
        iCardService.Result objResult = new ISB_iCard.iCardService.Result();
        public string TxnId = string.Empty;
        public decimal TotalAmount = 0;

        private void TnxDetails_Load(object sender, EventArgs e)
        {
            this.KeyDown += new KeyEventHandler(this.OnKeyDown);
            GetItems();
            //lblTotalAmount.Text = strAmount;
        }

        private void GetItems()
        {
            try
            {
                TotalAmount = 0;
                objiCardService.Url = "http://192.168.2.112/ISB_Data/Service1.asmx";
                //objiCardService.Url = "http://172.16.0.248/ISB_Data/Service1.asmx";
                //objiCardService.Url = "http://172.18.8.64:81/ISB_Data/Service1.asmx";
                objResult = objiCardService.GetItems(TxnId);
                if (objResult.IsSuccess.Equals(false))
                {
                    throw new Exception(objResult.ErrorMessage);
                }
                DataSet ds = objResult.ReturnObject;
                //MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("No Items found.");
                    this.Close();
                }
                else
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        ListViewItem li = new ListViewItem((i + 1).ToString());
                        li.SubItems.Add(Convert.ToString(ds.Tables[0].Rows[i]["disp_name"]));
                        if (Convert.ToString(ds.Tables[0].Rows[i]["C"]) == "C")
                        {
                            li.SubItems.Add("0");
                            li.SubItems.Add("0");
                        }
                        else
                        {
                            li.SubItems.Add(Convert.ToString(ds.Tables[0].Rows[i]["qty"]));
                            li.SubItems.Add(Convert.ToString(ds.Tables[0].Rows[i]["TAmt"]));
                            TotalAmount += System.Decimal.Parse(Convert.ToString(ds.Tables[0].Rows[i]["TAmt"]));
                        }

                        listView1.Items.Add(li);
                    }
                    lblTotalAmount.Text = "Rs:" + TotalAmount.ToString("0000.00");
                }
            }
            catch (Exception ex)
            {
                statusBar1.Text = "Error Fetching Items";
                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            //switch (e.KeyCode)
            //{
            //    case Keys.Escape:
            //        this.Hide();
            //        //MessageBox.Show("Pressed Escape Key");
            //        break;
            //}
        }

        private void listView1_KeyDown(object sender, KeyEventArgs e)
        {
            //switch (e.KeyCode)
            //{
            //    case Keys.Escape:
            //        this.Hide();
            //        MessageBox.Show("Pressed Escape Key");
            //        break;
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}